package com.xuebank.nfe.nfecar;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.MediaController;

/**
 * Created by admin Mr.WANG 2018/12/18.
 */

public class MyMediaController extends MediaController {
    private Activity mActivity;

    private View mRoot;

    public MyMediaController(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyMediaController(Context context, boolean useFastForward) {
        super(context, useFastForward);
    }

    public MyMediaController(Activity activity) {
        super(activity);
        mActivity = activity;
    }

    @Override
    public void setAnchorView(View view) {
        super.setAnchorView(view);
//        SeekBar newSeekBar = (SeekBar) LayoutInflater.from(getContext()).inflate(
//                R.layout.media_controllers, null);
//        //mRoot是MediaController的布局，它是一个view对象
//        Field mRoot = null;
//        try {
//            mRoot = MediaController.class
//                    .getDeclaredField("mRoot");
//        } catch (NoSuchFieldException e) {
//            e.printStackTrace();
//        }
//        mRoot.setAccessible(true);
//        ViewGroup mRootVg = null;//jni方法，传入对象实例
//        try {
//            mRootVg = (ViewGroup) mRoot.get(this);
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        }
//        ViewGroup vg = findSeekBarParent(mRootVg);//递归查找包含seekbar的ViewGroup
//        //Seekbar的索引
//        int seekbar_index = 1;
//        for (int i = 0; i < vg.getChildCount(); i++) {//获取子控件在容器里的索引
//            if (vg.getChildAt(i) instanceof SeekBar) {
//                seekbar_index = i;
//                break;
//            }
//        }
//
//
//        Field mCurrentTime = null;
//        try {
//            mCurrentTime = MediaController.class.getDeclaredField("mCurrentTime");
//        } catch (NoSuchFieldException e) {
//            e.printStackTrace();
//        }
//        mCurrentTime.setAccessible(true);
//        TextView tv_currenttime = null;
//        try {
//            tv_currenttime = (TextView) mCurrentTime.get(this);
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        }
//        LinearLayout.LayoutParams tv_currenttime_lp = (LinearLayout.LayoutParams) tv_currenttime.getLayoutParams();//获取textview的布局参数
//        int tv_currenttime_index = vg.indexOfChild(tv_currenttime);//1.获取子控件在容器里的位置 （具体的控件）
//        //播放时间textview控件放在seekbar后
//        vg.removeViewAt(tv_currenttime_index);//把原来的textview先移除
//        vg.addView(tv_currenttime, seekbar_index, tv_currenttime_lp);
//        //播放时长和视频时长之间添加一个分隔符‘/’
//        TextView split = new TextView(mActivity);
//        split.setText("/");
//        split.getPaint().setFakeBoldText(true);
////        split.setPadding(DensityUtil.dip2px(context, 4), dip2px(context, 4), DensityUtil.dip2px(context, 4), 0);
//        vg.addView(split, seekbar_index+1, tv_currenttime_lp);
//        //播放/暂停按钮
//        Field mPauseButton = null;
//        try {
//            mPauseButton = MediaController.class.getDeclaredField("mPauseButton");
//        } catch (NoSuchFieldException e) {
//            e.printStackTrace();
//        }
//        mPauseButton.setAccessible(true);
//        ImageButton ib_pause_button = null;
//        try {
//            ib_pause_button = (ImageButton) mPauseButton.get(this);
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        }
//        ib_pause_button.setBackgroundColor(mActivity.getResources().getColor(R.color.colornull));
//        LinearLayout ll_btn_parents = ((LinearLayout) ib_pause_button.getParent());
//        ll_btn_parents.removeView(ib_pause_button);//删除pause按钮使其可以添加到其他容器里
//        ll_btn_parents.setVisibility(LinearLayout.GONE);//隐藏容器和其他按钮
//        vg.addView(ib_pause_button, 0);
//
//
//
//
//        final ImageButton ibFullScreen= (ImageButton) LayoutInflater.from(mActivity).inflate(R.layout.my_imagebutton,null);
//        LinearLayout.LayoutParams ibFullScreenParams = new LinearLayout.LayoutParams(
//                pHeight,pHeight);
//        vg.addView(ibFullScreen,ibFullScreenParams);
//        ibFullScreen.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if(isFullScreen){
//                    ibFullScreen.setImageDrawable(context.getResources().getDrawable(R.mipmap.fullscreen));
//                }else{
//                    ibFullScreen.setImageDrawable(context.getResources().getDrawable(R.mipmap.smallscreen));
//                }
//                mFullScreenListener.OnFullScreen(isFullScreen);
//                MyMediaController.this.show();//刷新MediaController的存在时间
//                isFullScreen=!isFullScreen;
//            }
//        });

    }



//
//    @Override
//    public void show() {
//        super.show();
//        ((ViewGroup) mActivity.findViewById(android.R.id.content))
//                .removeView(mView);
//        ((ViewGroup) mActivity.findViewById(android.R.id.content))
//                .addView(mView);
//
//    }
//
//    @Override
//    public void hide() {
//        super.hide();
//        ((ViewGroup) mActivity.findViewById(android.R.id.content))
//                .removeView(mView);
//    }
}
